/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MantPlantillaMarcoReferencia.java
 *
 * Created on 12/09/2011, 03:48:29 PM
 */

package GUI.AdministracionPlantillas;

import BE.PlantillaMarcoReferencia;
import BL.PlantillaMarcoReferenciaBl;
import GUI.AdministracionUsuarios.UtilUsuarios;
import GUI.Principal;
import GUI.Utils.Utils;
import java.awt.Color;
import java.awt.Font;
import java.util.List;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.TableView.TableRow;

/**
 *
 * @author CarLita
 */
public class MantPlantillaMarcoReferencia extends javax.swing.JPanel {
    Principal ventanaPrincipal;
    PlantillaMarcoReferenciaBl plantillaMRBl;
    PlantillaMarcoReferencia marcoReferenciaSeleccionado;
    /** Creates new form MantPlantillaMarcoReferencia */
    
    
    public MantPlantillaMarcoReferencia(Principal ventanaPrincipal) {        
        initComponents();
        this.ventanaPrincipal= ventanaPrincipal;
        plantillaMRBl = new PlantillaMarcoReferenciaBl();
        buscarPlantillas();
        bloquearPorPermisos();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        txtMarcoReferencia = new javax.swing.JTextField();
        txtAreaEspecializacion = new javax.swing.JTextField();
        btnBuscar = new javax.swing.JButton();
        btnNuevo = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblPlantillas = new javax.swing.JTable();
        btnAgregar = new javax.swing.JButton();
        btnEditar = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        btnLimpiar = new javax.swing.JButton();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Búsqueda"));

        jLabel1.setText("Nombre:");

        jLabel2.setText("Marco de Referencia:");

        jLabel3.setText("Area de Especialización:");

        btnBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/AdministracionPlantillas/find.png"))); // NOI18N
        btnBuscar.setText("Buscar");
        btnBuscar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnBuscar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        btnNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/AdministracionPlantillas/new doc.png"))); // NOI18N
        btnNuevo.setText("Nueva Plantilla");
        btnNuevo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnNuevo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addGap(24, 24, 24)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE)
                    .addComponent(txtMarcoReferencia)
                    .addComponent(txtAreaEspecializacion))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE)
                .addComponent(btnBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnNuevo)
                .addGap(27, 27, 27))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(txtMarcoReferencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtAreaEspecializacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(btnBuscar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnNuevo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel2.setEnabled(false);

        tblPlantillas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Id", "Nombre", "Marco de Referencia", "Especialización"
            }
        ));
        tblPlantillas.setCellEditor(null);
        tblPlantillas.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tblPlantillas.getColumn("Id").setWidth(0); tblPlantillas.getColumn("Id").setMinWidth(0); tblPlantillas.getColumn("Id").setMaxWidth(0);
        tblPlantillas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tblPlantillasMousePressed(evt);
            }
        });
        jScrollPane1.setViewportView(tblPlantillas);

        btnAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/AdministracionPlantillas/new doc.png"))); // NOI18N
        btnAgregar.setText("Agregar");
        btnAgregar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnAgregar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarActionPerformed(evt);
            }
        });

        btnEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/AdministracionPlantillas/edit.gif"))); // NOI18N
        btnEditar.setText("Editar");
        btnEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditarActionPerformed(evt);
            }
        });

        btnEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/AdministracionPlantillas/minus white.png"))); // NOI18N
        btnEliminar.setText("Eliminar");
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 603, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnEliminar, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                    .addComponent(btnEditar, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                    .addComponent(btnAgregar, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE))
                .addGap(27, 27, 27))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btnAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(13, 13, 13)
                        .addComponent(btnEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnEliminar)))
                .addContainerGap(31, Short.MAX_VALUE))
        );

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/AdministracionPlantillas/cancelar.png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        btnLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/AdministracionPlantillas/limpiar.png"))); // NOI18N
        btnLimpiar.setText("Limpiar");
        btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 816, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 18, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(200, 200, 200)
                            .addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(30, 30, 30)
                            .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGap(0, 18, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 478, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 15, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(10, 10, 10)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(10, 10, 10)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(0, 15, Short.MAX_VALUE)))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoActionPerformed
        crearNuevaPlantilla();
        limpiar();
}//GEN-LAST:event_btnNuevoActionPerformed

    private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarActionPerformed
        crearNuevaPlantilla();
        limpiar();
}//GEN-LAST:event_btnAgregarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        ventanaPrincipal.panelContenedor.removeAll();
        ventanaPrincipal.panelContenedor.repaint();
        ventanaPrincipal.mostrarInicio();
}//GEN-LAST:event_btnCancelarActionPerformed

    private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarActionPerformed
        limpiar();
}//GEN-LAST:event_btnLimpiarActionPerformed

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        String msjError = validarInput();
        if (msjError.isEmpty()){
            colorearTexto();
            limpiarTabla();
            buscarPlantillas();
        }
        else JOptionPane.showMessageDialog(this, msjError, "Caracteres Ilegales", JOptionPane.ERROR_MESSAGE);
        
    }//GEN-LAST:event_btnBuscarActionPerformed

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
        int fila = tblPlantillas.getSelectedRow();
        if (fila==-1){
            JOptionPane.showMessageDialog(this, "Seleccione el marco de referencia a eliminar", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        //int idPlantillaSeleccionada = get
        int idMarco = Integer.parseInt(tblPlantillas.getValueAt(tblPlantillas.getSelectedRow(), 0).toString());
        int salida = JOptionPane.showConfirmDialog(this, "Desea eliminar el registro seleccionado?", null, JOptionPane.YES_NO_OPTION);
        if (salida == JOptionPane.YES_OPTION)
            {
                boolean eliminado = plantillaMRBl.eliminar(idMarco);
                if (eliminado){
                    JOptionPane.showMessageDialog(this, "El marco de referencia seleccionado fue eliminado", "Confirmacion", JOptionPane.INFORMATION_MESSAGE);
                    buscarPlantillas();
                }
                 else{
                        JOptionPane.showMessageDialog(this, "Ocurrió un error en la eliminación. \nPor favor, intente nuevamente.", "Error", JOptionPane.ERROR_MESSAGE);
                 }
            }
            limpiar();
            buscarPlantillas();
    }//GEN-LAST:event_btnEliminarActionPerformed

    private void btnEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarActionPerformed
        if (tblPlantillas.getSelectedRow()==-1) {
            JOptionPane.showMessageDialog(this, "Seleccione el marco de referencia a editar", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        getMarcoSeleccionado();
        this.setVisible(false);
        ventanaPrincipal.panelPlantillas.mantenimientoPlantillas.setVisible(false);
        ventanaPrincipal.panelPlantillas.add(ventanaPrincipal.panelPlantillas.creacionPlantillas);
        ventanaPrincipal.panelPlantillas.creacionPlantillas.setMarcoRef(marcoReferenciaSeleccionado, Principal.MODO_EDICION);
        ventanaPrincipal.panelPlantillas.creacionPlantillas.setVisible(true);
        limpiar();
    }//GEN-LAST:event_btnEditarActionPerformed

    private void tblPlantillasMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblPlantillasMousePressed
        if (evt.getClickCount()>1){
            leerMarcoReferencia();
        }
    }//GEN-LAST:event_tblPlantillasMousePressed

    private void crearNuevaPlantilla() {
        this.setVisible(false);
        ventanaPrincipal.panelPlantillas.mantenimientoPlantillas.setVisible(false);
        ventanaPrincipal.panelPlantillas.add(ventanaPrincipal.panelPlantillas.creacionPlantillas);
        ventanaPrincipal.panelPlantillas.creacionPlantillas.setearModo(Principal.MODO_CREACION);
        ventanaPrincipal.panelPlantillas.creacionPlantillas.setVisible(true);
    }

    public void buscarPlantillas() {
        PlantillaMarcoReferencia plantillaBusqueda = new PlantillaMarcoReferencia();
        plantillaBusqueda.setNombre(txtNombre.getText().trim());
        plantillaBusqueda.setNombreMarcoReferencia(txtMarcoReferencia.getText().trim());
        plantillaBusqueda.setAreaEspecializacion(txtAreaEspecializacion.getText().trim());
        List listaPlantillas = plantillaMRBl.buscarPorCriterios(plantillaBusqueda);
        llenarTabla(listaPlantillas);
        ocultarIdTabla();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregar;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnEditar;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JButton btnNuevo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblPlantillas;
    private javax.swing.JTextField txtAreaEspecializacion;
    private javax.swing.JTextField txtMarcoReferencia;
    private javax.swing.JTextField txtNombre;
    // End of variables declaration//GEN-END:variables

    private void llenarTabla(List listaPlantillas) {
        Vector<String> tableHeaders = new Vector<String>();
        Vector tableData = new Vector();
        tableHeaders.add("Id");
        tableHeaders.add("Nombre");
        tableHeaders.add("Marco de Referencia");
        tableHeaders.add("Especializacion");

        for(Object o : listaPlantillas) {
            PlantillaMarcoReferencia plantilla = (PlantillaMarcoReferencia)o;
            Vector<Object> fila = new Vector<Object>();
            fila.add(plantilla.getIdPlantilla());
            fila.add(plantilla.getNombre());
            fila.add(plantilla.getNombreMarcoReferencia());
            fila.add(plantilla.getAreaEspecializacion());
            tableData.add(fila);
        }

        tblPlantillas.setModel(new DefaultTableModel(tableData, tableHeaders));

    }

    private void limpiarTabla() {
        
        tblPlantillas.setModel(new DefaultTableModel(
                new Object [][] {
                {null, null, null, null},
                {null, null, null, null}},
            new String [] {
                "Id", "Nombre", "Marco de Referencia", "Especialización"
            }));
        ocultarIdTabla();

    }

    private void ocultarIdTabla() {
        tblPlantillas.getColumn("Id").setWidth(0);
        tblPlantillas.getColumn("Id").setMinWidth(0);
        tblPlantillas.getColumn("Id").setMaxWidth(0);
    }

    private void getMarcoSeleccionado() {
        int idMarco = Integer.parseInt(tblPlantillas.getValueAt(tblPlantillas.getSelectedRow(), 0).toString());
        System.out.println("Id seleccionado:"+ idMarco);
        marcoReferenciaSeleccionado = plantillaMRBl.buscarPorId(idMarco);
    }

    public void limpiar() {
        txtAreaEspecializacion.setText("");
        txtMarcoReferencia.setText("");
        txtNombre.setText("");
        buscarPlantillas();
        colorearTexto();
        marcoReferenciaSeleccionado = null;
    }

    private void colorearTexto(){
        txtAreaEspecializacion.setForeground(Color.black);
        txtMarcoReferencia.setForeground(Color.black);
        txtNombre.setForeground(Color.black);
    }

    private void leerMarcoReferencia() {        
        getMarcoSeleccionado();
        this.setVisible(false);
        ventanaPrincipal.panelPlantillas.mantenimientoPlantillas.setVisible(false);
        ventanaPrincipal.panelPlantillas.add(ventanaPrincipal.panelPlantillas.creacionPlantillas);
        ventanaPrincipal.panelPlantillas.creacionPlantillas.setMarcoRef(marcoReferenciaSeleccionado, Principal.MODO_LECTURA);
        ventanaPrincipal.panelPlantillas.creacionPlantillas.setVisible(true);
        limpiar();
    }

    private String validarInput() {
        boolean nombreOk = Utils.validarAlfaNumerico(txtNombre.getText());
        boolean marcoOk = Utils.validarAlfaNumerico(txtMarcoReferencia.getText());
        boolean areaOk = Utils.validarAlfaNumerico(txtAreaEspecializacion.getText());
        String msjError="";
        if (!nombreOk){
            msjError+= "El criterio de búsqueda para el título contiene caracteres no permitidos. \n";
            txtNombre.setForeground(Color.red);
        }
        if (!marcoOk){
            msjError+= "El criterio de búsqueda para el marco de referencia contiene caracteres no permitidos. \n";
            txtMarcoReferencia.setForeground(Color.red);
        }
        if (!areaOk){
            msjError+= "El criterio de búsqueda para el área de especialización contiene caracteres no permitidos. \n";
            txtAreaEspecializacion.setForeground(Color.red);
        }

        if (!msjError.isEmpty()){
            msjError+="Recuerde que sólo se permiten caracteres alfanuméricos, espacios en blanco y . - , ( ) ";
        }
        return msjError;
    }

    private void bloquearPorPermisos() {
        if (ventanaPrincipal.getPermisos().getPermisoMarco().indexOf(UtilUsuarios.VER)>-1)
        {
            btnEditar.setVisible(false);
            btnEditar.setEnabled(false);
            btnAgregar.setEnabled(false);
            btnAgregar.setVisible(false);
            btnEliminar.setEnabled(false);
            btnEliminar.setVisible(false);
            btnNuevo.setEnabled(false);
            btnNuevo.setVisible(false);
        }        
        if (ventanaPrincipal.getPermisos().getPermisoMarco().indexOf(UtilUsuarios.CREAR)>-1)
        {
            btnEditar.setVisible(false);
            btnEditar.setEnabled(false);
            btnAgregar.setEnabled(true);
            btnAgregar.setVisible(true);
            btnEliminar.setEnabled(true);
            btnEliminar.setVisible(true);
            btnNuevo.setEnabled(true);
            btnNuevo.setVisible(true);
         
        }                
        if (ventanaPrincipal.getPermisos().getPermisoMarco().indexOf(UtilUsuarios.EDITAR)>-1)
        {
            btnEditar.setVisible(true);
            btnEditar.setEnabled(true);
            btnAgregar.setEnabled(true);
            btnAgregar.setEnabled(true);
            btnAgregar.setVisible(true);
            btnEliminar.setEnabled(true);
            btnEliminar.setVisible(true);
            btnNuevo.setEnabled(true);
            btnNuevo.setVisible(true);
         
        }
    }




}
